using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PersonDomain;
using ShivamEMR.Model.DataInterfaces.PersonDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Person.Controllers
{   
    public class PersonInformationController : Controller
    {
		private readonly IPersonInformationRepository personinformationRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PersonInformationController() //: this(new PersonInformationRepository())
        {
            personinformationRepository = Registry.RepositoryFactory.GetPersonInformationRepository();
        }

        public PersonInformationController(IPersonInformationRepository personinformationRepository)
        {
			this.personinformationRepository = personinformationRepository;
        }

        //
        // GET: /PersonInformation/

        public ViewResult Index()
        {
            return View(personinformationRepository.All);//Including(personinformation => personinformation.Persons));
        }

        //
        // GET: /PersonInformation/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(personinformationRepository.Find(id));
        }

        //
        // GET: /PersonInformation/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /PersonInformation/Create

        [HttpPost]
        public ActionResult Create(PersonInformation personinformation)
        {
            if (ModelState.IsValid) {
                personinformationRepository.Create(personinformation);
                personinformationRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /PersonInformation/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
             return View(personinformationRepository.Find(id));
        }

        //
        // POST: /PersonInformation/Edit/5

        [HttpPost]
        public ActionResult Edit(PersonInformation personinformation)
        {
            if (ModelState.IsValid) {
                personinformationRepository.Update(personinformation);
                personinformationRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /PersonInformation/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(personinformationRepository.Find(id));
        }

        //
        // POST: /PersonInformation/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var pi = personinformationRepository.Find(id);
            personinformationRepository.Delete(pi);
            personinformationRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

